home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / gs24src.zip / STD.H < prev    next >
C/C++ Source or Header  |  1992-03-25  |  13KB  |  320 lines

  1. /* Copyright (C) 1989, 1992 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* std.h */
  21. /* Standard definitions for Aladdin Enterprises code */
  22.  
  23. #ifndef std_INCLUDED
  24. #  define std_INCLUDED
  25.  
  26. /* Include the architecture definitions. */
  27. #include "arch.h"
  28. #define arch_ints_are_short (arch_sizeof_int == arch_sizeof_short)
  29.  
  30. /*
  31.  * Here we deal with the vagaries of various C compilers.  We assume that:
  32.  *    ANSI-standard Unix compilers define __STDC__.
  33.  *    Turbo C and Turbo C++ define __MSDOS__ and __TURBOC__.
  34.  *    Borland C++ defines __BORLANDC__, __MSDOS__, and __TURBOC__.
  35.  *    Microsoft C defines MSDOS.
  36.  *    Watcom C defines __WATCOMC__ and MSDOS.
  37.  * We arrange to define __MSDOS__ on all the MS-DOS platforms.
  38.  * Also, not used much here, but used in other header files, we assume:
  39.  *    Unix System V environments define USG or SYSV.
  40.  *      (GNU software uses the former, non-GNU tends to use the latter.)
  41.  *    VMS systems define VMS.
  42.  *    bsd 4.2 or 4.3 systems define BSD4_2.
  43.  *    POSIX-compliant environments define _POSIX_SOURCE.
  44.  *    Motorola 88K BCS/OCS systems defined m88k.
  45.  *
  46.  * We make fairly heroic efforts to confine all uses of these flags to
  47.  * header files, and never to use them in code.
  48.  */
  49.  
  50. #if defined(__STDC__) || defined(__MSDOS__)
  51. #  define __PROTOTYPES__ /* */
  52. #endif
  53.  
  54. /* Recognize USG and SYSV as synonyms.  GNU software uses the former, */
  55. /* non-GNU tends to use the latter.  We use the latter. */
  56. #ifdef USG
  57. #  define SYSV /* */
  58. #endif
  59.  
  60. /* Define dummy values for __FILE__ and __LINE__ if the compiler */
  61. /* doesn't provide these.  Note that places that use __FILE__ */
  62. /* must check explicitly for a null pointer. */
  63. #ifndef __FILE__
  64. #  define __FILE__ NULL
  65. #endif
  66. #ifndef __LINE__
  67. #  define __LINE__ 0
  68. #endif
  69.  
  70. /* Disable 'const' if the compiler can't handle it. */
  71. #ifndef __PROTOTYPES__
  72. #  define const /* */
  73. #endif
  74.  
  75. /* Disable MS-DOS specialized pointer types on non-MS-DOS systems. */
  76. /* Watcom C defines near, far, and huge as macros, so we must undef them. */
  77. #ifndef __TURBOC__
  78. #  undef near
  79. #  define near /* */
  80. #  undef far
  81. #  define far /* */
  82. #  undef huge
  83. #  define huge /* */
  84. #  define _cs /* */
  85. #  define _ds /* */
  86. /* _es is never safe to use */
  87. #  define _ss /* */
  88. #endif
  89.  
  90. /* Define a couple of useful language extensions. */
  91. /* Get the size of a statically declared array. */
  92. #define countof(a) (sizeof(a) / sizeof((a)[0]))
  93.  
  94. /* Define short names for the unsigned types. */
  95. typedef unsigned char byte;
  96. typedef unsigned char uchar;
  97. typedef unsigned short ushort;
  98. typedef unsigned int uint;
  99. typedef unsigned long ulong;
  100.  
  101. /* Since sys/types.h often defines one or more of these (depending on */
  102. /* the platform), we have to take steps to prevent name clashes. */
  103. /*** NOTE: This requires that you include std.h *before* any other ***/
  104. /*** header file that includes sys/types.h. ***/
  105. #define uchar uchar_
  106. #define uint uint_
  107. #define ushort ushort_
  108. #define ulong ulong_
  109. #include <sys/types.h>
  110. #undef uchar
  111. #undef uint
  112. #undef ushort
  113. #undef ulong
  114.  
  115. /* Maximum values for the unsigned types. */
  116. /* The "+0" is to get around apparent bugs in the UTek compiler. */
  117. #define max_uchar ((uchar)0xff + (uchar)0)
  118. #define max_ushort ((ushort)0xffff + (ushort)0)
  119. #define max_uint ((uint)0xffffffff + (uint)0)
  120. #define max_ulong ((ulong)0xffffffffL + (ulong)0)
  121.  
  122. /* Define a reliable arithmetic right shift. */
  123. /* Must use arith_rshift_1 for a shift by a literal 1. */
  124. #define arith_rshift_slow(x,n) ((x) < 0 ? ~(~(x) >> (n)) : (x) >> (n))
  125. #if arch_arith_rshift == 2
  126. #  define arith_rshift(x,n) ((x) >> (n))
  127. #  define arith_rshift_1(x) ((x) >> 1)
  128. #else
  129. #if arch_arith_rshift == 1        /* OK except for n=1 */
  130. #  define arith_rshift(x,n) ((x) >> (n))
  131. #  define arith_rshift_1(x) arith_rshift_slow(x,1)
  132. #else
  133. #  define arith_rshift(x,n) arith_rshift_slow(x,n)
  134. #  define arith_rshift_1(x) arith_rshift_slow(x,1)
  135. #endif
  136. #endif
  137.  
  138. /* The type to be used for comparing pointers for order (<, >=, etc.). */
  139. /* Turbo C large model doesn't compare pointers per se correctly. */
  140. #ifdef __MSDOS__
  141. typedef unsigned long ptr_ord_t;
  142. #else
  143. typedef char *ptr_ord_t;
  144. #endif
  145. /* Define all the pointer comparison operations. */
  146. #define _ptr_cmp(p1, rel, p2)  ((ptr_ord_t)(p1) rel (ptr_ord_t)(p2))
  147. #define ptr_le(p1, p2) _ptr_cmp(p1, <=, p2)
  148. #define ptr_lt(p1, p2) _ptr_cmp(p1, <, p2)
  149. #define ptr_ge(p1, p2) _ptr_cmp(p1, >=, p2)
  150. #define ptr_gt(p1, p2) _ptr_cmp(p1, >, p2)
  151. #define ptr_between(ptr, lo, hi)\
  152.   (ptr_ge(ptr, lo) && ptr_lt(ptr, hi))
  153.  
  154. /* In case stdio.h doesn't have these: */
  155. #ifndef min
  156. #  define min(a, b) ((a) < (b) ? (a) : (b))
  157. #endif
  158. #ifndef max
  159. #  define max(a, b) ((a) > (b) ? (a) : (b))
  160. #endif
  161.  
  162. /* VMS doesn't have the unlink system call.  Use delete instead. */
  163. #ifdef VMS
  164. #  define unlink(fname) delete(fname)
  165. #endif
  166.  
  167. /* K&R specifies that float parameters get converted to double. */
  168. /* However, if we pass a float to a function that has been declared */
  169. /* with a prototype, and the parameter has been declared as float, */
  170. /* the ANSI standard specifies that the parameter is left as float. */
  171. /* To avoid problems when mixing ANSI and non-ANSI compilation, */
  172. /* we declare all float parameters as double. */
  173. typedef double floatp;
  174.  
  175. /* If we are debugging, make all static variables and procedures public */
  176. /* so they get passed through the linker. */
  177. #ifdef NOPRIVATE
  178. # define private /* */
  179. #else
  180. # define private static
  181. #endif
  182.  
  183. /*
  184.  * Macros for argument templates.  ANSI C has these, as does Turbo C,
  185.  * but older pcc-derived (K&R) Unix compilers don't.  The syntax is
  186.  *    resulttype func(Pn(arg1, ..., argn));
  187.  */
  188.  
  189. #ifdef __PROTOTYPES__
  190. # define P0() void
  191. # define P1(t1) t1
  192. # define P2(t1,t2) t1,t2
  193. # define P3(t1,t2,t3) t1,t2,t3
  194. # define P4(t1,t2,t3,t4) t1,t2,t3,t4
  195. # define P5(t1,t2,t3,t4,t5) t1,t2,t3,t4,t5
  196. # define P6(t1,t2,t3,t4,t5,t6) t1,t2,t3,t4,t5,t6
  197. # define P7(t1,t2,t3,t4,t5,t6,t7) t1,t2,t3,t4,t5,t6,t7
  198. # define P8(t1,t2,t3,t4,t5,t6,t7,t8) t1,t2,t3,t4,t5,t6,t7,t8
  199. # define P9(t1,t2,t3,t4,t5,t6,t7,t8,t9) t1,t2,t3,t4,t5,t6,t7,t8,t9
  200. # define P10(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10) t1,t2,t3,t4,t5,t6,t7,t8,t9,t10
  201. # define P11(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11) t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11
  202. # define P12(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12) t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12
  203. #else
  204. # define P0() /* */
  205. # define P1(t1) /* */
  206. # define P2(t1,t2) /* */
  207. # define P3(t1,t2,t3) /* */
  208. # define P4(t1,t2,t3,t4) /* */
  209. # define P5(t1,t2,t3,t4,t5) /* */
  210. # define P6(t1,t2,t3,t4,t5,t6) /* */
  211. # define P7(t1,t2,t3,t4,t5,t6,t7) /* */
  212. # define P8(t1,t2,t3,t4,t5,t6,t7,t8) /* */
  213. # define P9(t1,t2,t3,t4,t5,t6,t7,t8,t9) /* */
  214. # define P10(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10) /* */
  215. # define P11(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11) /* */
  216. # define P12(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12) /* */
  217. #endif
  218.  
  219. /* Types for client-supplied allocate and free procedures. */
  220. /* For accountability, debugging, and error messages, */
  221. /* we pass an identifying string to alloc and free. */
  222. /* Note that the arguments are like calloc, not like malloc, */
  223. /* but an alloc procedure doesn't clear the block. */
  224. typedef char *(*proc_alloc_t)(P3(unsigned num_elements, unsigned element_size, const char *client_name));
  225. typedef void (*proc_free_t)(P4(char *data, unsigned num_elements, unsigned element_size, const char *client_name));
  226.  
  227. /* Standard error printing macros. */
  228. /* Use dprintf for messages that just go to dstderr, */
  229. /* eprintf for error messages to estderr that include the program name, */
  230. /* lprintf for debugging messages that should include line number info. */
  231.  
  232. /* dstderr and estderr may be redefined. */
  233. #define dstderr stderr
  234. #define estderr stderr
  235.  
  236. #define dputc(chr) fputc(chr, dstderr)
  237. #define dputs(str) fputs(str, dstderr)
  238. #define dprintf(str)\
  239.   fprintf(dstderr, str)
  240. #define dprintf1(str,arg1)\
  241.   fprintf(dstderr, str, arg1)
  242. #define dprintf2(str,arg1,arg2)\
  243.   fprintf(dstderr, str, arg1, arg2)
  244. #define dprintf3(str,arg1,arg2,arg3)\
  245.   fprintf(dstderr, str, arg1, arg2, arg3)
  246. #define dprintf4(str,arg1,arg2,arg3,arg4)\
  247.   fprintf(dstderr, str, arg1, arg2, arg3, arg4)
  248. #define dprintf5(str,arg1,arg2,arg3,arg4,arg5)\
  249.   fprintf(dstderr, str, arg1, arg2, arg3, arg4, arg5)
  250. #define dprintf6(str,arg1,arg2,arg3,arg4,arg5,arg6)\
  251.   fprintf(dstderr, str, arg1, arg2, arg3, arg4, arg5, arg6)
  252. #define dprintf7(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7)\
  253.   fprintf(dstderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
  254. #define dprintf8(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)\
  255.   fprintf(dstderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
  256. #define dprintf9(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)\
  257.   fprintf(dstderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
  258. #define dprintf10(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)\
  259.   fprintf(dstderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)
  260.  
  261. #ifdef PROGRAM_NAME
  262. #  define _epn fprintf(estderr, PROGRAM_NAME),
  263. #else
  264. #  define _epn /* */
  265. #endif
  266.  
  267. #define eprintf(str)\
  268.   (_epn fprintf(estderr, str))
  269. #define eprintf1(str,arg1)\
  270.   (_epn fprintf(estderr, str, arg1))
  271. #define eprintf2(str,arg1,arg2)\
  272.   (_epn fprintf(estderr, str, arg1, arg2))
  273. #define eprintf3(str,arg1,arg2,arg3)\
  274.   (_epn fprintf(estderr, str, arg1, arg2, arg3))
  275. #define eprintf4(str,arg1,arg2,arg3,arg4)\
  276.   (_epn fprintf(estderr, str, arg1, arg2, arg3, arg4))
  277. #define eprintf5(str,arg1,arg2,arg3,arg4,arg5)\
  278.   (_epn fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5))
  279. #define eprintf6(str,arg1,arg2,arg3,arg4,arg5,arg6)\
  280.   (_epn fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6))
  281. #define eprintf7(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7)\
  282.   (_epn fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7))
  283. #define eprintf8(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)\
  284.   (_epn fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8))
  285. #define eprintf9(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)\
  286.   (_epn fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9))
  287. #define eprintf10(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)\
  288.   (_epn fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10))
  289.  
  290. #if __LINE__                /* compiler provides it */
  291. #  define _epl _epn fprintf(estderr, "%s(%d): ", __FILE__, __LINE__),
  292. #else
  293. #  define _epl _epn
  294. #endif
  295.  
  296. #define lprintf(str)\
  297.   (_epl fprintf(estderr, str))
  298. #define lprintf1(str,arg1)\
  299.   (_epl fprintf(estderr, str, arg1))
  300. #define lprintf2(str,arg1,arg2)\
  301.   (_epl fprintf(estderr, str, arg1, arg2))
  302. #define lprintf3(str,arg1,arg2,arg3)\
  303.   (_epl fprintf(estderr, str, arg1, arg2, arg3))
  304. #define lprintf4(str,arg1,arg2,arg3,arg4)\
  305.   (_epl fprintf(estderr, str, arg1, arg2, arg3, arg4))
  306. #define lprintf5(str,arg1,arg2,arg3,arg4,arg5)\
  307.   (_epl fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5))
  308. #define lprintf6(str,arg1,arg2,arg3,arg4,arg5,arg6)\
  309.   (_epl fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6))
  310. #define lprintf7(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7)\
  311.   (_epl fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7))
  312. #define lprintf8(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)\
  313.   (_epl fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8))
  314. #define lprintf9(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)\
  315.   (_epl fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9))
  316. #define lprintf10(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10)\
  317.   (_epl fprintf(estderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10))
  318.  
  319. #endif                    /* std_INCLUDED */
  320.